﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Action.SPI;

namespace T.FAS.Runtime.Action.Service
{
    public class ActionRTPHelpCacheService
    {
        private ConcurrentDictionary<string, DataBaseInfo> dataBaseInfoCache;

        private static object syncobj = new object();

        private static ActionRTPHelpCacheService instance;

        private ActionRTPHelpCacheService()
        {
            dataBaseInfoCache = new ConcurrentDictionary<string, DataBaseInfo>(StringComparer.OrdinalIgnoreCase);
        }

        public static ActionRTPHelpCacheService GetInstance()
        {
            if (instance == null)
            {
                lock (syncobj)
                {
                    if (instance == null)
                    {
                        instance = new ActionRTPHelpCacheService();
                    }
                }
            }

            return instance;
        }
        public void AddDataBaseInfoCache(DataBaseInfo info)
        {
            dataBaseInfoCache[info.Code] = info;
        }
        public DataBaseInfo GetDataBaseInfoFromLocalCache(string databaseCode)
        {
            if (dataBaseInfoCache.ContainsKey(databaseCode) == false)
            {
                return null;
            }
            return dataBaseInfoCache[databaseCode];
        }
    }
}
